package com.itheima.d7_interface_demo;

import java.util.ArrayList;

public class OperatorTwo implements StudentOperator {

    @Override
    public void PrintAll(ArrayList<Student> stus) {
        System.out.println("------------打印全部学生信息---------------");
        int count1 = 0;
        int count2 = 0;
        for (int i = 0; i < stus.size(); i++) {
            Student student = stus.get(i);
            System.out.println(student.getName() + " "+ student.getSex() + "" + student.getScore());
            if(student.getSex()=='男'){
                count1++;
            }else {
                count2++;
            }
        }
        System.out.println("男生人数：" + count1 + "女生人数：" + count2);
        System.out.println("-----------------------------------------");
    }

    @Override
    public void PrintAvg(ArrayList<Student> stus) {
        double avg = 0;
        double maxScore = stus.get(0).getScore();
        double minScore = stus.get(0).getScore();
        for (int i = 0; i < stus.size(); i++) {
            Student student = stus.get(i);
            avg += student.getScore();
            if(student.getScore()>maxScore){
                maxScore = student.getScore();
            }
            if(student.getScore()<minScore){
                minScore = student.getScore();
            }
        }
        System.out.println("最高分：" + maxScore);
        System.out.println("最低分：" + minScore);
        System.out.println("平均成绩为：" + (avg - maxScore-minScore) / (stus.size() -2 ));
    }
}
